{% extends "layout.html" %}

{% block content %}
<div class="container-fluid">
    <ol class="breadcrumb">
        <li><a href="/">后台管理</a></li>
        <li><a href="javascript:void(0);" onclick="$('#menu-message').trigger('click');">留言管理</a></li>
        <li class="active">留言列表</li>
    </ol>

    <!-- content -->
    <div class="table-responsive">
        {# <table class="table table-striped"> #}
        <table class="table table-hover">
            <thead>
            <tr>
                <th>消息明细ID</th>
                <th>发送用户</th>
                <th>接收用户</th>
                <th>消息</th>
                <th>时间</th>
                <th>操作</th>
            </tr>
            </thead>
            <tbody>
            {% for msg, user_profile_put, user_profile_get in pagination.items %}
            <tr class="text-muted">
                <td>{{ msg.id }}</td>
                <td>{{ user_profile_put.nickname | default('系统消息') }} [{{ user_profile_put.user_id }}]</td>
                <td>{{ user_profile_get.nickname }} [{{ user_profile_get.user_id }}]</td>
                <td>{{ msg.content }}</td>
                <td>{{ moment(msg.create_time).format('YYYY-MM-DD HH:mm:ss') }}</td>
                <td>
                    <a href="javascript:void(0);" onclick="msg_delete({{ msg.id }});" rel="tooltip" title="删除"><span class="glyphicon glyphicon-trash"></span></a>
                </td>
            </tr>
            {% endfor %}
            </tbody>
        </table>
        {# 翻页 #}
        {% from "macros.html" import render_pagination %}
        {{ render_pagination(pagination, 'message.lists') }}
    </div>


</div>

{% endblock %}

{% block extra_js %}
<script>
    // 留言删除
    function msg_delete(msg_id){
        if(confirm("删除数据不能恢复，是否确认删除?"))
        {
            // console.log(user_id);
            $.getJSON('{{ url_for('message.ajax_delete') }}',
            {
                msg_id: msg_id
            }, function (result) {
                if(result.hasOwnProperty('error')){
                    alert(result.error);
                }else {
                    alert(result.success);
                    window.location.reload();
                }
            });
            return false;
        }
    }
</script>
{% endblock %}